package main.java.eu.jpereira.trainings.designpatterns.creational.builder.xml;

import java.util.Iterator;

import main.java.eu.jpereira.trainings.designpatterns.creational.builder.ReportBodyBuilder;
import main.java.eu.jpereira.trainings.designpatterns.creational.builder.model.ReportBody;

public class XMLReportBodyBuilder extends ReportBodyBuilder 
{

        private XMLReportBody reportBody = new XMLReportBody();
       
        @Override
        public ReportBody getReportBody() 
        {
                reportBody.putContent("<sale><customer><name>");
                reportBody.putContent(customerName);
                reportBody.putContent("</name><phone>");
                reportBody.putContent(phoneNumber);
                reportBody.putContent("</phone></customer>");
                reportBody.putContent("<items>");
                Iterator<Item> it = soldItems.iterator();
                while ( it.hasNext() ) 
                {
                        Item item = it.next();
                        reportBody.putContent("<item><name>");
                        reportBody.putContent(item.name);
                        reportBody.putContent("</name><quantity>");
                        reportBody.putContent(item.quantity);
                        reportBody.putContent("</quantity><price>");
                        reportBody.putContent(item.price);
                        reportBody.putContent("</price></item>");
                }
                reportBody.putContent("</items></sale>");
               
                return reportBody;
        }

}